<?php

namespace App\Http\Controllers\Api\Complaint;

use App\Http\Controllers\Controller;
use App\Services\complaintService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class ComplaintController extends Controller
{
    /**
     * 投诉某一个工作
     * @param Request $request
     * @return JsonResponse
     */
    public function complaint(Request $request): JsonResponse
    {
        $rule = [
            "user_id"    => "required",
            "recruit_id" => "required",
            "type"       => "required",
            "reason"     => "required"
        ];
        $input       = $request->input();
        $validateRet = Validator::make($input, $rule);
        if ($validateRet->fails()) {
            return result(1, $validateRet->errors()->first());
        }

        try {
            (new complaintService())->complaintRecruit($input);
        } catch (\Exception $e) {
            return result(1, $e->getMessage());
        }
        return result(0, '操作成功');
    }
}
